package com.xbongbong.parent.condition;

import com.xbongbong.parent.condition.impl.ConditionFormDefaultHandlerImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * 业务规则条件中字段工厂
 * @author 吴峰
 * @version v1.0
 * @date 2020/3/3 19:38
 * @since v1.0
 */
@Component
public class ConditionFieldHandlerFactory {

    @Resource
    private Map<Integer, ConditionFieldHandler> conditionFieldHandlerMap;
    @Resource
    private ConditionFormDefaultHandlerImpl conditionFormDefaultHandler;
    /**
     * 业务规则条件本表单字段处理声明
     * @param fieldType
     * @return
     */
    public ConditionFieldHandler getHandlerByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new ConditionFormComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new ConditionFormComboCheckHandlerImpl();
//            case SERIALNO:
//                return new ConditionFormSerialNoHandlerImpl();
//            case ADDTIME:
//                return new ConditionFormAddTimeHandlerImpl();
//            case UPDATETIME:
//                return new ConditionFormUpdateTimeHandlerImpl();
//            case DATAID:
//                return new ConditionFormDataIdHandlerImpl();
//            case LINK_DATA:
//                return new ConditionFormLinkDataHandlerImpl();
//            case CREATORID:
//                return new ConditionFormCreatorIdHandlerImpl();
////            case DEPARTMENTID:
////                return new ConditionFormDepartmentIdHandlerImpl();
//            case STAGE_THRUSTER:
//                return new ConditionFormStageHandlerImpl();
//            default:
//                return new ConditionFormDefaultHandlerImpl();
        ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerMap.get(fieldType);
        if (Objects.isNull(conditionFieldHandler)) {
            return conditionFormDefaultHandler;
        }
        return conditionFieldHandler;
    }
    /**
     * 业务规则条件目标表单字段处理声明
     * @param fieldType
     * @return
     */
    public ConditionFieldHandler getHandlerTargetFormByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new ConditionFormComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new ConditionFormComboCheckHandlerImpl();
//            case LINK_BUSINESS_SINGLE:
//                return new ConditionFormLinkBusinessHandlerImpl();
//            case LINK_DATA:
//                return new ConditionFormLinkDataHandlerImpl();
//            case DATAID:
//                return new ConditionFormDataIdHandlerImpl();
//            case SERIALNO:
//                return new ConditionFormSerialNoHandlerImpl();
//            case DATETIME:
//                return new ConditionFormDateTimeHandlerImpl();
//            case STAGE_THRUSTER:
//                return new ConditionFormStageHandlerImpl();
//            default:
//                return new ConditionFormDefaultHandlerImpl();
        ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerMap.get(fieldType);
        if (Objects.isNull(conditionFieldHandler)) {
            return conditionFormDefaultHandler;
        }
        return conditionFieldHandler;
    }
    /**
     * 业务规则条件固定值处理声明
     * @param fieldType
     * @return
     */
    public ConditionFieldHandler getHandlerFixedValueByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new ConditionFormComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new ConditionFormComboCheckHandlerImpl();
//            case USER:
//            case DEPT:
//            case USER_GROUP:
//            case DEPT_GROUP:
//                return new ConditionFormUserAndDeptHandlerImpl();
//            case STAGE_THRUSTER:
//                return new ConditionFormStageHandlerImpl();
//            default:
//                return new ConditionFormDefaultHandlerImpl();
        ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerMap.get(fieldType);
        if (Objects.isNull(conditionFieldHandler)) {
            return conditionFormDefaultHandler;
        }
        return conditionFieldHandler;
    }

    /**
     * 关联数据条件固定值处理
     * @param fieldType
     * @return
     */
    public ConditionFieldHandler getRelyFormFixedValueByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new ConditionFormComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new ConditionFormComboCheckHandlerImpl();
//            case USER:
//            case DEPT:
//            case USER_GROUP:
//            case DEPT_GROUP:
//                return new ConditionFormUserAndDeptHandlerImpl();
//            case STAGE_THRUSTER:
//                return new ConditionFormStageHandlerImpl();
//            default:
//                return new ConditionFormDefaultHandlerImpl();
        ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerMap.get(fieldType);
        if (Objects.isNull(conditionFieldHandler)) {
            return conditionFormDefaultHandler;
        }
        return conditionFieldHandler;
    }
    /**
     * 多条件处理(关联数据、系统关联数据和数据联动共用)
     * @param fieldType
     * @return
     * @author xingxing.xiao
     */
    public ConditionFieldHandler getHandlerRelyFormByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new ConditionFormComboHandlerImpl();
//            case USER:
//            case DEPT:
//            case USER_GROUP:
//            case DEPT_GROUP:
//                return new ConditionFormUserAndDeptHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new ConditionFormComboCheckHandlerImpl();
//            case DATETIME:
//                return new ConditionFormDateTimeHandlerImpl();
//            case SERIALNO:
//                return new ConditionFormSerialNoHandlerImpl();
//            case ADDRESS:
//            case LOCATION:
//                return new ConditionFormAddressHandlerImpl();
//            case LINK_BUSINESS_SINGLE:
//            case LINK_DATA:
//            case DATAID:
//                return new ConditionFormLinkDataHandlerImpl();
//            case STAGE_THRUSTER:
//                return new ConditionFormStageHandlerImpl();
//            default:
//                // TEXT, TEXTAREA, NUM
//                return new ConditionFormDefaultHandlerImpl();
//        }
        ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerMap.get(fieldType);
        if (Objects.isNull(conditionFieldHandler)) {
            return conditionFormDefaultHandler;
        }
        return conditionFieldHandler;
    }

    /**
     * 业务规则条件固定值处理声明
     * @param fieldType
     * @return
     */
    public ConditionFieldHandler handlerPreConditionByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new ConditionFormComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new ConditionFormComboCheckHandlerImpl();
//            case LINK_BUSINESS_SINGLE:
//                return new ConditionFormLinkDataHandlerImpl();
//            case USER:
//            case DEPT:
//            case USER_GROUP:
//            case DEPT_GROUP:
//            case DEPARTMENTID:
//            case CREATORID:
//                return new ConditionFormUserAndDeptHandlerImpl();
//            case DATETIME:
//            case ADDTIME:
//            case UPDATETIME:
//                return new ConditionFormDateTimeHandlerImpl();
//            case STAGE_THRUSTER:
//                return new ConditionFormStageHandlerImpl();
//            default:
//                return new ConditionFormDefaultHandlerImpl();
//        }
        ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerMap.get(fieldType);
        if (Objects.isNull(conditionFieldHandler)) {
            return conditionFormDefaultHandler;
        }
        return conditionFieldHandler;
    }
}
